Skip to content

Honour Retry-After on a GitHub rate limit [patch] - #388

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/honour-retry-after
Oct 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/honour-retry-after

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Part of #385. This is the GitHub half; the Azure DevOps half is explained below and left open on the issue.

What was wrong

ParseRateLimitResetTime read only X-RateLimit-Reset. On a secondary (abuse) limit that header is still the end of the primary hourly window, often 30–60 minutes away, and the Retry-After GitHub sends (typically 60 s) was ignored. GetRateLimitWaitTime() then paused every GitHub request for the 10-minute cap.

Change

ParseRateLimitResetTime now follows GitHub's guidance:

  1. Retry-After present: retry after that many seconds (an HTTP-date value is also accepted).
  2. Otherwise, X-RateLimit-Remaining: 0: wait until X-RateLimit-Reset, as before.
  3. Otherwise: back off for one minute (SecondaryRateLimitBackoff).

A response with no headers still returns null, so the existing incremental backoff applies.

GitHubRateLimitResetTests covers each acceptance case. The headline case is a 403 with Remaining: 4000, Reset: now+45m and Retry-After: 60, which now gives now+60s.

Not in this PR: the Azure DevOps 429

The issue suggests reading Retry-After off the VssServiceResponseException. That exception carries no response or headers; its only public members are HttpStatusCode and the message. Capturing the header means adding a DelegatingHandler to the VssConnection pipeline that records the last 429's Retry-After. That can't be checked without a live organization, since building a session authenticates against dev.azure.com, so it is noted on the issue rather than shipped untested.

Verification

  • With the old logic restored temporarily, the Retry-After, no-Retry-After secondary and HTTP-date cases fail. The primary-reset case passes either way because that behaviour is unchanged. With the fix, all four pass.
  • dotnet test --project BuildMonitor.Test: 147/147 pass.
  • dotnet build -c Release: 0 warnings.

Generated by Claude Code

Only X-RateLimit-Reset was read, which on a secondary limit is the end of
the primary hourly window, so a limit that asked for 60 s paused polling
for the 10-minute cap. Use Retry-After when it is sent, X-RateLimit-Reset
only when the primary budget is spent, and otherwise back off a minute.

Part of #385 (the GitHub half).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2nrCvY4DyoEF72Nk1
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant